using System;
using infoMECHANICA.NHibernateORM.CriteriaBuilder;

namespace infoMECHANICA.NHibernateORM.TestMappings
{
    /// <summary>
    /// Recorder of Job class/Jobs table
    /// </summary>
    [Serializable]
    public class JobRec : CriteriaRecorder<JobRec,Job>
    {
        private ICriterionProperty<int> _JobId;
        private ICriterionProperty<string> _Name;
        private ISubcriteriaProperty<EmployeeRec> _EmployeesByJob;


        /// <summary>
        /// Recorder property for JobId column (PRIMARY KEY!)
        /// </summary>
        public ICriterionProperty<int> JobId
        {
            get 
            {
                if (this._JobId == null)
                {
                    this._JobId = new CriterionProperty<int>("JobId", this);
                }
                
                return _JobId; 
            }               
        }
        
        /// <summary>
        /// Gets the name of dto identifier property (when it's different than "Id")
        /// </summary>
        public override string GetIdPropertyName()
        {
            return "JobId";
        }
 
        /// <summary>
        /// Recorder property for Name column
        /// </summary>
        public ICriterionProperty<string> Name
        {
            get 
            {
                if (this._Name == null)
                {
                    this._Name = new CriterionProperty<string>("Name", this);
                }
                
                return _Name; 
            }               
        }        


        /// <summary>
        /// Recorder property of many-to-many relationship between Employees and Jobs tables
        /// </summary>        
        public virtual ISubcriteriaProperty<EmployeeRec> EmployeesByJob
        {
            get
            {
                if (this._EmployeesByJob == null)
                {
                    this._EmployeesByJob = new SubcriteriaProperty<EmployeeRec>("Job");
                }
                
                return _EmployeesByJob;         
            }
        }        

        /// <summary>
        /// Constructor, creates the recorder with no parent
        /// </summary>
        public JobRec()
        {
        }
        
        /// <summary>
        /// Constuctor, creates CriteriaRecorder and sets its parent
        /// </summary>
        /// <param name="parent">Parent of this recorder</param>
        public JobRec (ICriteriaRecorder parent)
            : base(parent)
        {
        }
    }
}